/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.football.lottery.ui;

import java.awt.Color;
import java.awt.Component;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

/**
 *
 * @author I am god
 */
public class JTableCellRenderer implements TableCellRenderer
{
  @Override
  public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
      int row, int column)
  {
    CheckboxPanel panel = new CheckboxPanel();
    // columns number:   0       1     2     3     4       5       6          7      8
    // columns name:  orderNo, type, time, host, score, guest, compensation, bet, preventBet
    switch (column)
    {
      case 0:
        panel.add(new JLabel(((Integer) value).toString()));
        break;

      case 1:
      case 3:
      case 4:
      case 5:
      case 6:
        panel.add(new JLabel(((String) value)));
        break;

      case 2:
        SimpleDateFormat df = new SimpleDateFormat("MM-dd hh:mm");
        Date gateTime = (Date) value;
        panel.add(new JLabel(df.format(gateTime)));
        break;

      case 7:
      case 8:
        panel = new CheckboxPanel((String) value);
        break;
    }
    if (row % 2 == 0)
    {
      panel.setBackground(Color.WHITE);  
      panel.setCheckBoxBackground(Color.WHITE);
    }
    if (isSelected)
    {  
      panel.setBackground(Color.GREEN);
      panel.setCheckBoxBackground(Color.GREEN);
    }  
    return panel;
  }
}
